package com.itcast.springboot.controller;

import com.itcast.springboot.bean.SongList;
import com.itcast.springboot.service.SongListService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

@Api(tags = "歌单列表相关的请求")
@RestController
@CrossOrigin
public class SongListController {

    @Autowired
    SongListService songListService;

    //通过id查询
    @ApiOperation("通过id查询歌单信息")
    @ApiImplicitParams(
            @ApiImplicitParam(name = "slid", value = "歌单id")
    )
    @GetMapping("/songlist/{slid}")
    public SongList getSongListById(@PathVariable("slid") Integer slid) {
        SongList songList = songListService.getSongListById(slid);
        return songList;
    }

    //in查询，查询多首歌曲信息
    @ApiOperation("in查询，查询多首歌曲信息")
    @ApiImplicitParams(
            @ApiImplicitParam(name = "slids", value = "多个歌单id")
    )
    @GetMapping("/songlists/{slids}")
    public List<SongList> getSongListsByIds(@PathVariable("slids") List<Integer> slids) {
        return songListService.getSongListsByIds(slids);
    }

    //根据用户的听歌类型随机抽取出20首歌曲
    @ApiOperation("根据用户的听歌类型随机抽取出20首歌曲")
    @ApiImplicitParams(
            @ApiImplicitParam(name = "sts", value = "多个歌曲类型")
    )
    @GetMapping("/songListsRand/{sts}")
    public List<SongList> getSongListsRand(@PathVariable("sts") List<String> sts) {
        return songListService.getSongListsRand(sts);
    }

    //根据歌曲类型和用户心情挑出出对应的歌曲信息
    @ApiOperation("根据歌曲类型和用户心情挑出出对应的歌曲信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "songType", value = "歌曲类型"),
            @ApiImplicitParam(name = "mood", value = "用户心情")
    })
    @GetMapping("/songLists/{songType}/{mood}")
    public List<SongList> getSongListsBySongTypeAndMood(@PathVariable("songType") String songType, @PathVariable("mood") String mood) {
        return songListService.getSongListsBySongTypeAndMood(songType, mood);
    }
    //通过歌曲类型、歌曲名字、作者查询
    @ApiOperation("通过歌曲类型、歌曲名字、作者查询")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "songType", value = "歌曲类型"),
            @ApiImplicitParam(name = "songName", value = "歌曲名字"),
            @ApiImplicitParam(name = "author", value = "作者")
    })
    @GetMapping({"/songListsTrim/{songType}/{songName}/{author}"})
    public List<SongList> getSongListsByStAndNameAndAu(@PathVariable(value = "songType", required = false) String songType,
                                                       @PathVariable(value = "songName", required = false) String songName,
                                                       @PathVariable(value = "author", required = false) String author){
        return songListService.getSongListsByStAndNameAndAu(songType, songName, author);
    }


    @ApiOperation("通过id删除歌单")
    @ApiImplicitParams(
            @ApiImplicitParam(name = "slid", value = "歌单id")
    )
    //通过id进行删除
    @DeleteMapping("/songlist/{slid}")
    public Integer deleteSongList(@PathVariable("slid") Integer slid) {
        Integer result = songListService.deleteSongList(slid);
        return result;
    }
    //增加歌单（包含上传文件）
    @ApiOperation("增加歌单（包含上传文件）")
    @PostMapping("/songlistUpload")
    public Integer insertSongListUpload(@RequestParam(value = "songFile", required = false) MultipartFile songFile,
                                  @RequestParam(value = "songPhoto", required = false) MultipartFile songPhoto,
                                  SongList songList) {
        return songListService.insertSongListUpload(songFile, songPhoto, songList);
    }
    //增加歌单
    @ApiOperation("增加歌单")
    @PostMapping("/songlist")
    public Integer insertSongList(@RequestBody SongList songList) {
        return songListService.insertSongList(songList);
    }
    //增加歌曲
    @ApiOperation("上传歌曲")
    @PostMapping("/songFile")
    public String insertSongFile(MultipartFile songFile){
        return songListService.insertSongFile(songFile);
    }
    //增加歌曲图片
    @ApiOperation("上传歌曲图片")
    @PostMapping("/songPhoto")
    public String insertSongPhoto(MultipartFile songPhoto){
        return songListService.insertSongPhoto(songPhoto);
    }

    @ApiOperation("修改歌单")
    @PutMapping("/songlist")
    public Integer updateSongList(@RequestBody SongList songList) {
        return songListService.updateSongList(songList);
    }
}
